/*     */ package com.wgcloud.controller;
/*     */ 
/*     */ import cn.hutool.json.JSONObject;
/*     */ import cn.hutool.json.JSONUtil;
/*     */ import com.github.pagehelper.PageInfo;
/*     */ import com.wgcloud.entity.HeathMonitor;
/*     */ import com.wgcloud.entity.HeathState;
/*     */ import com.wgcloud.service.DashboardService;
/*     */ import com.wgcloud.service.HeathMonitorService;
/*     */ import com.wgcloud.service.HeathStateService;
/*     */ import com.wgcloud.service.LogInfoService;
/*     */ import com.wgcloud.util.DateUtil;
/*     */ import com.wgcloud.util.PageUtil;
/*     */ import com.wgcloud.util.ResDataUtils;
/*     */ import com.wgcloud.util.TokenUtils;
/*     */ import com.wgcloud.util.license.LicenseUtil;
/*     */ import com.wgcloud.util.staticvar.StaticKeys;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.annotation.Resource;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.Model;
/*     */ import org.springframework.web.bind.annotation.RequestBody;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/heathMonitor"})
/*     */ public class HeathMonitorController
/*     */ {
/*  48 */   private static final Logger logger = LoggerFactory.getLogger(com.wgcloud.controller.HeathMonitorController.class);
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private HeathMonitorService heathMonitorService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private HeathStateService heathStateService;
/*     */   
/*     */   @Resource
/*     */   private LogInfoService logInfoService;
/*     */   
/*     */   @Resource
/*     */   private DashboardService dashboardService;
/*     */   
/*     */   @Autowired
/*     */   private TokenUtils tokenUtils;
/*     */ 
/*     */   
/*     */   @ResponseBody
/*     */   @RequestMapping({"agentList"})
/*     */   public String agentList(@RequestBody String paramBean) {
/*  71 */     if (!StaticKeys.LICENSE_STATE.equals("1")) {
/*  72 */       return ResDataUtils.resetErrorJson("请先升级到专业版");
/*     */     }
/*  74 */     JSONObject agentJsonObject = (JSONObject)JSONUtil.parse(paramBean);
/*  75 */     if (!this.tokenUtils.checkAgentToken(agentJsonObject)) {
/*  76 */       logger.error("token is invalidate");
/*  77 */       return ResDataUtils.resetErrorJson("token is invalidate");
/*     */     } 
/*  79 */     Map<String, Object> params = new HashMap<>();
/*     */     try {
/*  81 */       params.put("active", "1");
/*  82 */       List<HeathMonitor> heathMonitorList = this.heathMonitorService.selectAllByParams(params);
/*  83 */       return ResDataUtils.resetSuccessJson(heathMonitorList);
/*  84 */     } catch (Exception e) {
/*  85 */       logger.error("agent获取监控服务接口信息错误", e);
/*  86 */       this.logInfoService.save("agent获取监控服务接口信息错误", e.toString(), "1");
/*  87 */       return ResDataUtils.resetErrorJson(e.toString());
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"list"})
/*     */   public String heathMonitorList(HeathMonitor heathMonitor, Model model, HttpServletRequest request) {
/* 100 */     Map<String, Object> params = new HashMap<>();
/*     */     
/*     */     try {
/* 103 */       LicenseUtil.maxLicense_10(model, request);
/*     */ 
/*     */       
/* 106 */       StringBuffer url = new StringBuffer();
/* 107 */       String appName = null;
/* 108 */       String heathStatus = null;
/* 109 */       if (!StringUtils.isEmpty(heathMonitor.getAppName())) {
/* 110 */         appName = heathMonitor.getAppName();
/* 111 */         params.put("appName", appName.trim());
/* 112 */         url.append("&appName=").append(appName);
/*     */       } 
/* 114 */       if (!StringUtils.isEmpty(heathMonitor.getHeathStatus())) {
/* 115 */         heathStatus = heathMonitor.getHeathStatus();
/* 116 */         params.put("heathStatus", heathStatus.trim());
/* 117 */         url.append("&heathStatus=").append(heathStatus);
/*     */       } 
/*     */       
/* 120 */       PageInfo<HeathMonitor> pageInfo = this.heathMonitorService.selectByParams(params, heathMonitor.getPage().intValue(), heathMonitor.getPageSize().intValue());
/* 121 */       for (HeathMonitor heathMonitor1 : pageInfo.getList()) {
/* 122 */         if (StringUtils.isEmpty(heathMonitor1.getResKeyword())) {
/* 123 */           heathMonitor1.setResKeyword("");
/*     */         }
/*     */       } 
/* 126 */       PageUtil.initPageNumber(pageInfo, model);
/* 127 */       model.addAttribute("pageUrl", "/heathMonitor/list?1=1" + url.toString());
/* 128 */       model.addAttribute("page", pageInfo);
/* 129 */       model.addAttribute("heathMonitor", heathMonitor);
/* 130 */     } catch (Exception e) {
/* 131 */       logger.error("查询服务心跳监控错误", e);
/* 132 */       this.logInfoService.save("查询服务心跳监控错误", e.toString(), "1");
/*     */     } 
/*     */     
/* 135 */     return "heath/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"save"})
/*     */   public String saveHeathMonitor(HeathMonitor heathMonitor, Model model, HttpServletRequest request) {
/*     */     try {
/* 150 */       if (StringUtils.isEmpty(heathMonitor.getId())) {
/* 151 */         this.heathMonitorService.save(heathMonitor);
/*     */       } else {
/* 153 */         this.heathMonitorService.updateById(heathMonitor);
/*     */       }
/*     */     
/* 156 */     } catch (Exception e) {
/* 157 */       logger.error("保存服务心跳监控错误", e);
/* 158 */       this.logInfoService.save("保存服务心跳监控错误", e.toString(), "1");
/*     */     } 
/* 160 */     return "redirect:/heathMonitor/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"edit"})
/*     */   public String edit(Model model, HttpServletRequest request) {
/* 174 */     String errorMsg = "编辑服务心跳监控";
/* 175 */     String id = request.getParameter("id");
/* 176 */     HeathMonitor heathMonitor = new HeathMonitor();
/*     */     try {
/* 178 */       if (StringUtils.isEmpty(id)) {
/* 179 */         model.addAttribute("heathMonitor", heathMonitor);
/*     */ 
/*     */         
/* 182 */         Map<String, Object> params = new HashMap<>();
/* 183 */         int dbSize = this.heathMonitorService.countByParams(params);
/* 184 */         if (dbSize >= 10 && !StaticKeys.LICENSE_STATE.equals("1")) {
/* 185 */           return "redirect:/heathMonitor/list?liceFlage=1";
/*     */         }
/*     */ 
/*     */         
/* 189 */         return "heath/add";
/*     */       } 
/*     */ 
/*     */       
/* 193 */       heathMonitor = this.heathMonitorService.selectById(id);
/* 194 */       model.addAttribute("heathMonitor", heathMonitor);
/* 195 */     } catch (Exception e) {
/* 196 */       logger.error(errorMsg, e);
/* 197 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 199 */     return "heath/add";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"view"})
/*     */   public String view(Model model, HttpServletRequest request) {
/* 212 */     String errorMsg = "查看服务心跳统计图表错误";
/* 213 */     String id = request.getParameter("id");
/* 214 */     String date = request.getParameter("date");
/* 215 */     HeathMonitor heathMonitor = new HeathMonitor();
/*     */     try {
/* 217 */       heathMonitor = this.heathMonitorService.selectById(id);
/* 218 */       Map<String, Object> params = new HashMap<>();
/* 219 */       model.addAttribute("heathMonitor", heathMonitor);
/*     */       
/* 221 */       if (StringUtils.isEmpty(date)) {
/* 222 */         date = DateUtil.getCurrentDate();
/*     */       }
/* 224 */       this.dashboardService.setDateParam(date, params);
/* 225 */       model.addAttribute("datenow", date);
/* 226 */       model.addAttribute("dateList", this.dashboardService.getDateList());
/* 227 */       model.addAttribute("amList", this.dashboardService.getAmList());
/* 228 */       params.put("heathId", heathMonitor.getId());
/* 229 */       List<HeathState> appStateList = this.heathStateService.selectAllByParams(params);
/* 230 */       model.addAttribute("heathStateList", JSONUtil.parseArray(appStateList));
/* 231 */     } catch (Exception e) {
/* 232 */       logger.error(errorMsg, e);
/* 233 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 235 */     return "heath/view";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"del"})
/*     */   public String delete(Model model, HttpServletRequest request, RedirectAttributes redirectAttributes) {
/* 250 */     String errorMsg = "删除服务心跳监控错误";
/* 251 */     HeathMonitor HeathMonitor = new HeathMonitor();
/*     */     try {
/* 253 */       if (!StringUtils.isEmpty(request.getParameter("id"))) {
/* 254 */         String[] ids = request.getParameter("id").split(",");
/* 255 */         for (String id : ids) {
/* 256 */           HeathMonitor = this.heathMonitorService.selectById(id);
/* 257 */           this.logInfoService.save("删除服务接口：" + HeathMonitor.getAppName(), "删除服务接口：" + HeathMonitor.getAppName() + "：" + HeathMonitor.getHeathUrl(), "0");
/*     */         } 
/* 259 */         this.heathMonitorService.deleteById(ids);
/*     */       } 
/* 261 */     } catch (Exception e) {
/* 262 */       logger.error(errorMsg, e);
/* 263 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/*     */     
/* 266 */     return "redirect:/heathMonitor/list";
/*     */   }
/*     */ }


/* Location:              /Users/zhangyongxin/soft-install/wgcloud/wgcloud-v3.3.5/server/bank/wgcloud-server-release.jar!/BOOT-INF/classes/com/wgcloud/controller/HeathMonitorController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */